﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

namespace StuInfo
{
    public partial class Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["Id"]);
                Model.StuInfo info = StuInfoBLL.StuInfoListBLL.Read(id);
                if (info != null)
                {
                    text1.Value = info.Id.ToString();
                    text2.Value = info.Name;
                    TextBox1.Text = info.Comment;
                    if (info.Sex == "男")
                    {
                        RadioButton1.Checked = true;
                    }
                    else {
                        RadioButton2.Checked = true;
                    }
                }
                else
                {
                    Response.Redirect("~/StuInfo.aspx");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Model.StuInfo info = new Model.StuInfo()
            {
                Sex = RadioButton1.Checked ? "男" : "女",
                Name = text2.Value,
                Comment = TextBox1.Text,
                Id =Convert.ToInt32( text1.Value)
            };
            int num = StuInfoBLL.StuInfoListBLL.Update(info);
            if (num>0)
            {
                Response.Write("<script>alert('修改成功！');location='StuInfoListUI.aspx';</script>");
            }
        }
    }
}